package com.siwei.mes.controller.system;

import com.siwei.mes.entity.system.CompanyConfig;
import com.siwei.mes.service.system.CompanyConfigService;
import org.springframework.web.bind.annotation.*;
import com.siwei.mes.common.query.PageQuery;
import com.siwei.mes.common.result.ApiResult;
import com.siwei.mes.common.result.Json;
import com.siwei.mes.common.validator.AddGroup;
import com.siwei.mes.common.validator.PageGroup;
import com.siwei.mes.common.validator.UpdateGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.validation.annotation.Validated;

import static com.siwei.mes.common.exception.handler.MessageHandler.assertTrue;

import javax.annotation.Resource;

/**
 * 企业信息配置表相关
 *
 * @author makejava
 * @since 2024-11-21 20:02:56
 */
@Api(value = "企业信息配置表")
@RestController
@RequestMapping("companyConfig")
public class CompanyConfigController {
    @Resource
    private CompanyConfigService companyConfigService;

    @ApiOperation(value = "新增企业信息配置表")
    @PostMapping("/create")
    public Json create(@RequestBody @Validated(AddGroup.class) CompanyConfig entity) {
        return Json.succ().data(ApiResult.addColumn("id", companyConfigService.create(entity)));
    }

    @ApiOperation(value = "修改企业信息配置表")
    @PostMapping("/update")
    public Json update(@RequestBody @Validated(UpdateGroup.class) CompanyConfig entity) {
        companyConfigService.update(entity);
        return Json.succ().data(new ApiResult());
    }

    @ApiOperation(value = "删除企业信息配置表")
    @PostMapping("/delete")
    public Json delete(@RequestBody CompanyConfig entity) {
        companyConfigService.delete(entity.getId());
        return Json.succ().data(new ApiResult());
    }

    @ApiOperation(value = "分页获取企业信息配置表")
    @PostMapping("/page")
    public Json appPage(@RequestBody @Validated(PageGroup.class) PageQuery<CompanyConfig, CompanyConfig> query) {
        return Json.succ().data(companyConfigService.getPage(query));
    }

    @ApiOperation(value = "根据主键id获取企业信息配置表")
    @GetMapping("loadById")
    public Json loadById(@RequestParam("id") Long id) {
        return Json.succ().data(companyConfigService.loadById(id));
    }

    @ApiOperation(value = "获取所有企业信息配置表")
    @PostMapping("getAll")
    public Json getAll(@RequestBody CompanyConfig entity) {
        return Json.succ().data(ApiResult.addList(companyConfigService.getAll(entity)));
    }

}
